package QianFeng03;

import sun.awt.geom.AreaOp;

import java.io.OutputStream;

/*值传递与引用传递*/
public class Test5 {

    public static void main(String[] args) {
        //实例一：值传递
        int x = 10;
        method(x);
        System.out.println("x="+x);
        //实例二：引用传递
        Duck d = new Duck();
        method(d);
        System.out.println("Duck age = "+d.age);
        //实例三：String传递1
        String name = "小飞";
        method(name);
        System.out.println("name="+name);
	/*	//实例四：String传递2
		Person p = new Person();
		method(p);
		System.out.println("person name ="+p.name);    */
    }

    /*	//实例四：String传递2
        public static void method(Person per) {
            per.name = "备备";

        }   */
    //实例三：String传递1
    public static void method(String name) {
        name = "小备";

    }
    //实例二：引用传递
    public static void method(Duck duck) {
        duck.age = 5;

    }
    //实例一：值传递
    public static void method(int mx) {  //x把值传给mx
        mx = 20;

    }

}
//实例二：引用传递
class Duck{
    int age = 2;//省略封装
}
/*
//实例四：String传递2
class Person{
	String name = "飞飞"; //省略封装
}  */

